// https://leetcode.cn/problems/container-with-most-water/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    int maxArea(vector<int>& height) {
        int left = 0, right = height.size() - 1;
        int ans = 0;

        while (left < right) {
            int minHeight = min(height[left], height[right]);
            ans = max(ans, (right - left) * minHeight);

            if (height[left] <= height[right]) left++;
            else right--;
        }
        return ans;
    }
};